﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PSUA_RideSharing.ORM;


namespace PSUA_RideSharing.Pages.Login
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {

            using (RideShareEntities1 db = new RideShareEntities1())
            {
                tblMember member = new tblMember();
                tblMember holder = new tblMember();
                holder.fldUserID = txtLogin.Text;
                holder.fldPassword = txtLoginPassword.Text;

                var passes = from m in db.tblMembers
                             select m.fldPassword;

                var ids = from n in db.tblMembers
                          select n.fldUserID;

                foreach (var pass in passes)
                {
                    if (holder.fldPassword.Equals(pass))
                    {
                        foreach (var id in ids)
                        {
                            if (holder.fldUserID.Equals(id))
                            {
                                Session["username"] = txtLogin.Text;
                                this.Page.Response.Redirect("~/");
                            }
                        }
                    }
                }

                if ((Session["username"] == null))
                {
                    FailedLogInPanel.Visible = true;
                    txtLogin.Text = "";
                    txtLoginPassword.Text = "";
                }
            }
        }
    }
}